package com.goods.business.converter;


import com.goods.business.service.ProductService;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/business/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    //物资资料分页列表展示
    @GetMapping("/findProductList")
    public ResponseBean findProductList(@RequestParam Integer pageNum,
                                        @RequestParam Integer pageSize,
                                        @RequestParam String name,
                                        @RequestParam String categoryId,
                                        @RequestParam String supplier,
                                        @RequestParam Integer status,
                                        @RequestParam(required = false) long[] categorys
                                        ){
        PageVO<ProductVO> pageVO = productService.findProductList(pageNum,pageSize,name,categoryId,supplier,status,categorys);
        return ResponseBean.success(pageVO);
    }

    //添加物资
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ProductVO productVO){
        productService.add(productVO);
        return ResponseBean.success();
    }

    //编辑物资
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        ProductVO productVO = productService.edit(id);
        return ResponseBean.success(productVO);
    }

    //修改物资
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody ProductVO productVO){
        productService.update(id,productVO);
        return ResponseBean.success();
    }

    //物资回收站
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        productService.remove(id);
        return ResponseBean.success();
    }

    //物资恢复
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        productService.back(id);
        return ResponseBean.success();
    }

    //物资删除
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        productService.delete(id);
        return ResponseBean.success();
    }

    //物资审核
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        productService.publish(id);
        return ResponseBean.success();
    }
}
